package com.workerhelping.controller;

import com.workerhelping.dto.RabbitMQDTO;
import com.workerhelping.result.Result;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitMQController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送消息
     * @param rabbitMQDTO
     * @return
     */
    @PostMapping("/sendMsg")
    public boolean sendMsg(@RequestBody RabbitMQDTO rabbitMQDTO) {
        String exchange = rabbitMQDTO.getExchange();
        String routingKey = rabbitMQDTO.getRoutingKey();
        Object message = rabbitMQDTO.getMessage();
        rabbitTemplate.convertAndSend(exchange, routingKey, message);
        return true;
    }



}
